﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using UI.Lib;

namespace UI.ShopManagement
{
    public partial class FrmBas1a13Medit : UI.ParentForm.BaseMedit
    {
        private bool isReadOnly = false;

        public FrmBas1a13Medit(string modulecode, string action, string text, string key)
            : base(modulecode, action)
        {
            InitializeComponent();

            this.Text = text;
            this.Key = key;

            //回写的方法
            this.SaveCallFuntion = "Bas1a13Manager$SaveData"; //保存的方法
            IsAfterSaveCloseWin = false;
            this.allowDtlEmpty = false; //可能用户一次想把全部的记录删除
            if (!string.IsNullOrEmpty(this.Key))
            {
                LoadData();
                IsAfterSaveCloseWin = true;
            }
            this.Size = base.MaxWindow;
        }

        protected override bool BeforeDtlPopUp(string name, ref string where, ref string[] others)
        {
            if ("productcode" == name)
            {
                where = string.Format("a.status = '1' {0}", Context.GetAppKeyWhere("a.muser", true));
            }

            return true;
        }

        public override bool BeforePopWin(string name, ref string where, ref string[] others)
        {
            if ("sellercode" == name)
            {
                where = string.Format(" status ='1' {0} ", Context.GetAppKeyWhere("usercode", true));
            }
            return true;
        }

        //新增行后触发，用户只读概要
        protected override void AfterAddRow()
        {
            if (isReadOnly == true) return;

            this.tbSummary.Enable("sellercode", false);
        }

        protected override void AfterDelete()
        {
            if (this.dgvDtl.Rows.Count == 0)
            {
                this.tbSummary.Enable("sellercode", true);
                isReadOnly = false;
            }
        }

        protected override void AfterSaveData(bool isSuccess)
        {
            if (isSuccess)
            {
                this.tbSummary.Enable("sellercode", true);
                isReadOnly = false;
            }
        }

        //加载修改数据
        private void LoadData()
        {
            base.LoadEditData(null, string.Format(" listid ='{0}' ", this.Key));
            base.LoadDtlData(null, string.Format(" a.slistid ='{0}' ", this.Key));
        }


        public override void AfterDtlPopWin(string name, System.Collections.Hashtable data, bool ischange)
        {
            if ("productcode" == name)
            {
                this.dgvDtl.Focus("spno");
            }
        }
    }
}
